@echo off

set SVN_KEY_ROOT=HKCU\Software\Tigris.org\Subversion\Servers\global

if "%1"=="" (
	echo svnproxy - Set the proxy for SVN
	echo usage: svnproxy ADDRESS [PORT]
	echo   ADDRESS  - the IP address of proxy ^(e.g. 192.168.1.1^)
	echo   PORT     - the port of proxy, default to 80
	exit /B 1
)

if "%1"=="--remove" (
	reg delete %SVN_KEY_ROOT% /v http-proxy-host /f > NUL
	reg delete %SVN_KEY_ROOT% /v http-proxy-port /f > NUL 
	reg delete %SVN_KEY_ROOT% /v http-proxy-timeout /f > NUL
	echo Proxy is disabled on SVN.
) else (
	set ADDR=%1
	if "%2"=="" (
		set PORT=80
	) else (
		set PORT=%2
	)
	reg add %SVN_KEY_ROOT% /v http-proxy-host /t REG_SZ /d %ADDR% /f > NUL
	reg add %SVN_KEY_ROOT% /v http-proxy-port /t REG_SZ /d %PORT% /f > NUL
	reg add %SVN_KEY_ROOT% /v http-proxy-timeout /t REG_SZ /d 0 /f > NUL
	echo Proxy %ADDR%:%PORT% is applied on SVN.
)
